package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：碳汇因子键值转换
 * @Date：Create by 2023-11-23 16:12:43
 */
public interface ICarbonSinkFactorFilter {

	String TYPE = "type" ;

	String CARBON_SINK_FACTOR_TYPE = "ecp-admin.carbonSinkFactor.type" ;

	class CarbonSinkFactorExportFilter implements ValueFilter {

		private Map<String, String> typeMap;

		public CarbonSinkFactorExportFilter() {
			typeMap = DictHelper.i().stringVlMap(CARBON_SINK_FACTOR_TYPE);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, TYPE)) {
				return CommonUtils.orElse(typeMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

	class CarbonSinkFactorUploadFilter implements ValueFilter {

		private Map<String, String> typeMap;

		public CarbonSinkFactorUploadFilter() {
			typeMap = DictHelper.i().stringLvMap(CARBON_SINK_FACTOR_TYPE);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, TYPE)) {
				return CommonUtils.orElse(typeMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

}
